package cn.jw.framework.test.scheduletask;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import cn.hutool.extra.spring.SpringUtil;
import cn.jw.starter.common.scheduletask.JwScheduledTaskService;
import cn.jw.starter.common.scheduletask.ScheduledTaskCore;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;

/**
 * @author 王广帅
 * @version 1.0.0
 * @since 2024/8/15 23:25
 */
@Service
public class ScheduleTaskTestService implements ApplicationListener<ContextRefreshedEvent> {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private ScheduledTaskCore scheduledTaskCore;

    @PostConstruct
    public void init() {

    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        JwScheduledTaskService jwScheduledTaskService = SpringUtil.getBean(JwScheduledTaskService.class);
        jwScheduledTaskService.addTask("0 */5 * * * ?", TaskRunnable.class, "测试任务");
        jwScheduledTaskService.startAllTask();
    }
}
